# -*- coding: utf-8 -*-
import os
import numpy as np
import logging
#work_path = ''
#logging.basicConfig(level=logging.INFO,
#                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
#                    datefmt='%a, %d %b %Y %H:%M:%S',
#                    filename=work_path+'\\factorData.log',
#                    filemode='w')
dirs = 'logs'
if not os.path.exists(dirs):
    os.makedirs(dirs)
logging.basicConfig(filename='%s/info_leetcode.log' % dirs, level=logging.INFO,
                    format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

class Solution:
# =============================================================================
#     # NB的算法!利用
#     def rotate(self, matrix):
#         """
#         :type matrix: List[List[int]]
#         :rtype: void Do not return anything, modify matrix in-place instead.
#         """
#         print(*matrix[::-1])
#         print(zip(*matrix[::-1]))
#         matrix[:] = map(list,zip(*matrix[::-1]))  # zip(*) 是zip的反操作
#         return matrix
# =============================================================================
        
    pass
sss = Solution()
qqq= sss.rotate(matrix =
[
  [ 5, 1, 9,11],
  [ 2, 4, 8,10],
  [13, 3, 6, 7],
  [15,14,12,16]
], )
# =============================================================================
#     def isValidSudoku(self, board):
#         """
#         :type board: List[List[str]]
#         :rtype: bool
#         """
#         # 思路三： 思路二的另一种实现方式。代码更为简洁（借鉴）
#         Cell = [[] for i in range(9)]        # 定义包含9个空list的大的list           # 没有必要用dict,我们只某个数字关心有没有出现过
#         Col =  [[] for i in range(9)]
#         Row =  [[] for i in range(9)]
# 
#         for i,row in enumerate(board):                  # 将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列，同时列出数据和数据下标，一般用在 for 循环当中
#             for j,num in enumerate(row):
#                 if num != '.':
#                     k = (i//3)*3 + j//3   # 这个号,把9宫格分成0-8块,k就是某个元素在哪个块内,//为整数, /为float
#                     if num in Row[i] + Col[j] + Cell[k]:    # list的骚操作,将三个list顺序的拼接 
#                         return False
#                     Row[i].append(num)      # 表示某个元素不能出现在raw,column,cell,中!
#                     Col[j].append(num)
#                     Cell[k].append(num)
#         return True
# =============================================================================
# =============================================================================
#         # 思路一：复杂的分条判断   76ms
#         for i in range(9):
#             if 9 - len(set(board[i])) != board[i].count(".") - 1:     # 条件一
#                 return False
#             new_list = []                                                       
#             for j in range(9):                                         # 条件二
#                 if board[j][i] != '.' and board[j][i] in new_list:
#                     return False
#                 if board[j][i] != '.' and board[j][i] not in new_list:         
#                     new_list.append(board[j][i])   
#         aa,bb = [0,3,6],[0,3,6]
#         for a in aa:                    # 条件三
#             for b in bb:
#                 new_list = []
#                 for i in range(a,a+3):                
#                     for j in range(b,b+3):
#                         if board[i][j] != '.' and board[i][j] in new_list:
#                             return False
#                         if board[i][j] != '.' and board[i][j] not in new_list:         
#                             new_list.append(board[i][j])
#         return True
# =============================================================================
# =============================================================================
#     def twoSum(self, nums, target):
#         """
#         :type nums: List[int]
#         :type target: int
#         :rtype: List[int]
#         """
#         time1 = time.time()
#         for i in range(len(nums)):
#             result = target - nums[i]
#             if result in nums:
#                 key = nums.index(result)
#                 time2 =  time.time()
#                 time3 = time2 - time1
#                 return [i,key],time3
# =============================================================================
# =============================================================================
#     # 充分利用了交换的原则  不是0的位置,永远和第一个0的位置相换  
#     def moveZeroes(self, nums):
#         j = 0
#         for i in range(len(nums)):
#             if nums[i] != 0:
#                 nums[j], nums[i] = nums[i], nums[j]
#                 j += 1
#         return nums
# =============================================================================
# =============================================================================
#     def moveZeroes(self, nums):
#         """
#         :type nums: List[int]
#         :rtype: void Do not return anything, modify nums in-place instead.
#         """
#         n = nums.count(0)
#         for i in range(n):
#             nums.remove(0)
#         nums.extend([0]*n)
#         print([0]*n)
#         return nums  
# =============================================================================
# =============================================================================
#     def plusOne(self, digits):
#         """
#         :type digits: List[int]
#         :rtype: List[int]
#         """
#         # 完全适用于进位的情况~~!! 
#         num_digits = 0
#         nums = []
#         for i in range(len(digits)):
#             digits[i] = digits[i]*(10**(len(digits)-i-1)) 
#             num_digits += digits[i]
#         num_digits += 1
#         num_digits = list(str(num_digits))
#         for i in range(len(num_digits)):
#             nums.append(int(num_digits[i]))
#         return nums
# =============================================================================

# =============================================================================
#     def intersect(self, nums1, nums2):
#         """
#         :type nums1: List[int]
#         :type nums2: List[int]
#         :rtype: List[int]
#         """
#         import collections
#         a, b = map(collections.Counter, (nums1, nums2)) # 还是利用Counter模块,生成字典
#         # 这个很神奇的,输出两个字典中的共同元素,并且以小的数量为准!!典型的交集
#         print(list(a & b)) 
#         print(list((a & b).elements()))
#         return list((a & b).elements())
# =============================================================================
# =============================================================================
#     def singleNumber(self, nums):
#         """
#         :type nums: List[int]
#         :rtype: int
#         """
#         # 0 异或任何数都是任何数,异或除非用交换律之后能为0,否则要考虑到10进制转换为2进制再按位异或,
#         res = 0
#         for i in nums:
#             res ^= i
#         return res
#         # 用Counter计数模块
#         from collections import Counter
#         for key,value in Counter(nums).items():
#             if value == 1:
#                 return key
#          用字典的方法
#         s = {}
#         for i in nums:
#             if i in s.keys():
#                 s.pop[i]
#             else:
#                 s[i] = 1
#             return list(s.keys())[0]
# =============================================================================
# =============================================================================
#     此方法不完善,有bug,例如nums1 = [1,2,2,1,12,3414,142,12,5], nums2 = [2,2,5]
#     def intersect(self, nums1, nums2):
#         """
#         :type nums1: List[int]
#         :type nums2: List[int]
#         :rtype: List[int]
#         """
#         append_list = []
#         for i in nums1:
#             if i in nums2:
#                 append_list.append(i)
#                 nums1.remove(i)
#         return append_list
# =============================================================================
# =============================================================================
# from collections import Counter
# class Solution:
#     def containsDuplicate(self, nums):
#         """
#         :type nums: List[int]
#         :rtype: bool
#         """
#         dic = Counter(nums)
#         print(dic)
#         for value in dic.values():
#             if value > 1:
#                 return True
#             return False
#         nums = [1,2,3,1]
#         if len(nums) != len(set(nums)):
#             return False
#         return True
# =============================================================================
# =============================================================================
# class Solution:
#     def rotate(self, nums, k):
#         """
#         :type nums: List[int]
#         :type k: int
#         :rtype: void Do not return anything, modify nums in-place instead.
#         """
#         if len(nums)>1:
#             length = len(nums)
#             k = k%length
#             if k>0:
#                 move_num = 0
#                 move_pos = 0
#                 move_value = nums[move_pos]
#                 while move_num<length:
#                     next_pos = (move_pos+k)%length                    
#                     while next_pos!=move_pos:
#                         save_value = nums[next_pos]
#                         nums[next_pos] = move_value
#                         move_value = save_value
#                         next_pos=(next_pos+k)%length
#                         move_num+=1
#                     nums[move_pos]=move_value
#                     move_num+=1
#                     move_pos+=1
#                     move_value = nums[move_pos]   
# 
# def rotate_one(nums): # 右移1位
#     length = len(nums)
#     if length>1:
#         num_n_1 = nums[length-1]
#         num_k = length-1
#         while num_k>=1:
#             nums[num_k] = nums[num_k-1]     # 原来的第1位给第2位
#             num_k -= 1
#         nums[0] = num_n_1 # 最后一位给第0位
# def rotate_array(nums, k):
#     length = len(nums)
#     k = k%length
#     for rnum in range(k):
#         rotate_one(nums)
#      #rotate = [1,2,3,4,5,6,7]
#      #k=30
#      #length = len(rotate)
#      #k = k % length
#      #new_rotate = rotate[length-k:] + rotate[:length-k]     # 此处创建了O(n)空间复杂度的new_rotate
#      #for i in range(length):
#          #rotate[i] = new_rotate[i]
#      #return rotate
# =============================================================================
# =============================================================================
# def prices_array():
#     prices = [7,6,4,3,1]
#     profit = 0
#     for i in range(len(prices)-1):
#         if prices[i] < prices[i+1]:  
#             profit += prices[i+1] - prices[i]
#     return profit
# profit = prices_array()
# =============================================================================
# =============================================================================
# def del_array():
#     nums = [0,1,1,1,1,2,2,3,3,4]
#     k=0
#     for i in range(1,len(nums)):
#         if nums[i] != nums[k]:
#             k+=1
#             nums[k] = nums[i]
#         print('i:',i,'k:',k,'@@@@@@@@@@@@@@@@@@@@')    
#     del nums[k+1:len(nums)]
#     return nums, len(nums)       
# nums, nums_len = del_array()
# =============================================================================
# =============================================================================
# J = "aA"
# S = "aAAbbbb"
# def stone_jewel():
#     jewel_count = 0
#     for i in S:
#         if i in J:
#             jewel_count += 1
#     return jewel_count
# =============================================================================
